<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        canvas{
            border:1px solid black;
        }
    </style>
</head>
<body>
    <canvas id="c1" width="500" height="500">该浏览器不支持该标签</canvas>
    <script>
        // 1.获取画板的DOM对象(打开画图工具)
        var c1=document.getElementById("c1");
      
        // 2.获取画笔工具(笔触)
        var ctx=c1.getContext("2d");

        ctx.beginPath();//开启路径

        ctx.moveTo(100,100);
        ctx.lineTo(100,300);
        ctx.lineTo(300,300);
        ctx.stroke();
        ctx.strokeRect(320,320,100,100);
        ctx.fillRect(80,80,100,100);
        // ctx.strokeText(text,x,y,maxWidth)//绘制文本
        ctx.strokeText("hello",10,10);

        // context.clearRect(x,y,width,height);//清空画布
        // ctx.clearRect(90,90,300,400);
        // ctx.clearRect(0,0,500,500);//清空画布
    </script>

</body>
</html>